﻿using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Data;
using System.Data.Odbc;
using System.Data.OleDb;
using System.Runtime.Remoting.Messaging;

namespace AccSystem
{
    public struct Registration
    {
        public string name, sex, department, position, sg, numofyear, yrInService, age, bdate, address, housestatus, civilstatus, noOfChildren;
    }
    
    class ACcountSystem
    {
        OdbcConnection oc = new OdbcConnection();
        OdbcDataAdapter oda = new OdbcDataAdapter();
        public DataTable dt = new DataTable();

        public void Connect()
        {
            try
            {
                oc.ConnectionString = "Driver={MySQL ODBC 5.1 Drver};" +
                    "Server=localhost;" +
                    "Database=accountsystem" +
                    "UID=beeps;" +
                    "PWD=12345";
                oc.Open();
            }
            catch (Exception x)
            {

                oc.Close();
                return;
            }
        }
        public void close()
        {
            oc.Close();
        }
        public void Query(string sql)
        {
            try
            {
                dt = new DataTable();
                oda.SelectCommand = new OdbcCommand(sql, oc);
                dt.Clear();
                dt.Reset();
                oda.Fill(dt);
            }
            catch (Exception o) { }
        }

        public void Register_Record(Registration reg)
        {
            DataRow row = dt.NewRow();
            row[1] = reg.name;
            row[2] = reg.sex;
            row[3] = reg.department;
            row[4] = reg.position;
            row[5] = reg.sg;
            row[6] = reg.yrInService;
            row[7] = reg.numofyear;
            row[8] = reg.age;
            row[9] = reg.bdate;
            row[2] = reg.address;
            row[2] = reg.housestatus;
            row[2] = reg.civilstatus;
            row[2] = reg.noOfChildren;
            OdbcCommandBuilder builder = new OdbcCommandBuilder(oda);
            oda.Update(dt);

        }
    }
}